home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / CHECKLST.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  137 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.6  $
  6. //
  7. // Definition of class TCheckList, an ownerdrawn listbox to select multiple
  8. // items
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_CHECKLST_H)
  11. #define OWL_CHECKLST_H
  12.  
  13. #if !defined(OWL_LISTBOX_H)
  14. # include <owl/listbox.h>
  15. #endif
  16. #if !defined(OWL_CHECKBOX_H)
  17. # include <owl/checkbox.h>
  18. #endif
  19.  
  20. #if defined(BI_NAMESPACE)
  21. namespace OWL {
  22. #endif
  23.  
  24. // Generic definitions/compiler options (eg. alignment) preceeding the 
  25. // definition of classes
  26. #include <services/preclass.h>
  27.  
  28. //
  29. // class TCheckListItem
  30. // ~~~~~ ~~~~~~~~~~~~~~
  31. // Each item displayed and manipulated by TCheckList.
  32. //
  33. class _OWLCLASS TCheckListItem {
  34.   public:
  35.     TCheckListItem();
  36.     TCheckListItem(const char far* text, uint state = BF_UNCHECKED);
  37.    ~TCheckListItem();
  38.  
  39.     // State management
  40.     //
  41.     bool IsChecked() const;
  42.     bool IsIndeterminate() const;
  43.     void Toggle();
  44.     void Check();
  45.     void Uncheck();
  46.     void SetIndeterminate();
  47.     void SetThreeStates(bool);
  48.  
  49.     // Text management
  50.     //
  51.     void SetText(const char far* text);
  52.     void GetText(char far* buffer, int len);
  53.  
  54.   private:
  55.     char far* Text;
  56.     uint      State;
  57.     bool      HasThreeStates;
  58.  
  59.   friend class _OWLCLASS TCheckList;
  60. };
  61.  
  62.  
  63. //
  64. // class TCheckList
  65. // ~~~~~ ~~~~~~~~~~
  66. // An owner drawn listbox to select multiple items.
  67. //
  68. class _OWLCLASS TCheckList : public TListBox {
  69.   public:
  70.     // The constructors expect to be passed an array of TCheckListItems.
  71.     // The memory is owned by the callee.
  72.     //
  73.     TCheckList(TWindow* parent, int id, int x, int y, int w, int h,
  74.                TCheckListItem* items, int numItems,
  75.                TModule* module = 0);
  76.     TCheckList(TWindow* parent, int resourceId,
  77.                TCheckListItem* items, int numItems,
  78.                TModule* module = 0);
  79.    ~TCheckList();
  80.  
  81.   protected:
  82.     void SetupWindow();
  83.  
  84.     // Owner draw messages
  85.     //
  86.     void ODAFocus(DRAWITEMSTRUCT far& drawInfo);
  87.     void ODASelect(DRAWITEMSTRUCT far& drawInfo);
  88.     void ODADrawEntire(DRAWITEMSTRUCT far& drawInfo);
  89.     void PaintItem(DRAWITEMSTRUCT far& drawInfo);
  90.  
  91.     // Event handlers
  92.     //
  93.     void EvLButtonDown(uint modKeys, TPoint& point);
  94.     void EvChar(uint key, uint repeatCount, uint flags);
  95.     void Update();
  96.  
  97.     TCheckListItem* GetItemAtIndex(int index);
  98.  
  99.   private:
  100.     TCheckListItem* Items;
  101.     int             NumberOfItems;
  102.  
  103.   DECLARE_RESPONSE_TABLE(TCheckList);
  104. };
  105.  
  106. // Generic definitions/compiler options (eg. alignment) following the 
  107. // definition of classes
  108. #include <services/posclass.h>
  109.  
  110. #if defined(BI_NAMESPACE)
  111. } // namespace OWL
  112. #endif
  113.  
  114. //----------------------------------------------------------------------------
  115. // Inline Implementations
  116. //
  117.  
  118. //
  119. // Returns true if the item has been checked.
  120. //
  121. inline bool
  122. TCheckListItem::IsChecked() const
  123. {
  124.   return ToBool(State == BF_CHECKED);
  125. }
  126.  
  127. //
  128. // Returns true if the item is in the indeterminate state.
  129. //
  130. inline bool
  131. TCheckListItem::IsIndeterminate() const
  132. {
  133.   return ToBool(State == BF_GRAYED);
  134. }
  135.  
  136. #endif  // OWL_CHECKLIST_H
  137.